//
//  RTJHasInvestedController.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/11.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJHasInvestedController.h"
#import "RTJBidRecordsCell.h"
#import "RTJInvestmentDetailsController.h"

@interface RTJHasInvestedController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *data;

@end

@implementation RTJHasInvestedController

-(NSMutableArray *)data {
    if (!_data) {
        _data = [NSMutableArray array];
    }
    
    return _data;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.tableView.tableFooterView=[UIView new];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    self.tableView.estimatedRowHeight=300;
    
    [self loadData];

}

-(void)loadData{
    
    
    [SVProgressHUD  showWithStatus:nil];
    
    [self.view showEmptyViewWithStr:@"" image:nil callback:nil];
    
    [RTJNetWork asyncRequestWithURL:@"user/invite_list" params:nil method:GET zxCompletion:^(id data, NSInteger status, BOOL success, NSString *errorMsg) {
        
        [SVProgressHUD dismiss];
        [self.view removeEmptyView];
        
        if (success) {
            
            if ([data[@"status"]integerValue] == 1) {
                
                [self.data removeAllObjects];
                NSArray *arr = [NSArray array];
                arr = data[@"data"][@"load_user"];
                
                [self.data addObjectsFromArray:arr];
                
                if (self.data.count == 0) {
                    
                    [self.view showEmptyViewWithStr:@"您暂无好友投资数据" image:[UIImage imageNamed:@"kbylogo"] callback:^{
                        [self loadData];
                    }];
                    
                }else{
                    
                    [self.tableView reloadData];
                }
                
                
            }else{
                
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",data[@"msg"]]];
                [self.view showEmptyViewWithStr:data[@"msg"] image:[UIImage imageNamed:@"kbylogo"] callback:^{
                    [self loadData];
                }];
                
            }
            
        }else{
            
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",errorMsg]];
            [self.view showEmptyViewWithStr:errorMsg image:[UIImage imageNamed:@"kbylogo"] callback:^{
                [self loadData];
            }];

        }
        
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return  self.data.count;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return UITableViewAutomaticDimension;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * ID = @"RTJBidRecordsCell";
    
    RTJBidRecordsCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (!cell) {
        
        cell = [[NSBundle mainBundle] loadNibNamed:@"RTJBidRecordsCell" owner:self options:nil][2];
    }
    
    NSString *real_name = _data[indexPath.row][@"real_name"];
    cell.real_name.text = real_name.length!=0 ? real_name : @"--";
    cell.phoneLab.text = [NSString stringWithFormat:@"%@",_data[indexPath.row][@"mobile"]];
    cell.zhuceLab.text = [NSString stringWithFormat:@"注册时间：%@",_data[indexPath.row][@"create_time"]];
    cell.touziLab.text = [NSString stringWithFormat:@"投资金额：%@ 元",_data[indexPath.row][@"load_money"]];
    cell.dingdanLab.text = [NSString stringWithFormat:@"%@笔投资",_data[indexPath.row][@"load_count"]];
    cell.kehuPhone.hidden = YES;
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return  cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    RTJInvestmentDetailsController *vc = [[RTJInvestmentDetailsController alloc]init];
    vc.idStr = [NSString stringWithFormat:@"%@",_data[indexPath.row][@"id"]];
    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
